package main

import "fmt"

func main(){
    s := []int{1,2,3}

    // 截取s[1],s[2]不包含s[3]，所以s1 = []int{2,3}
    s1 := s[1:3]
    fmt.Printf("s1 = %v\n",s1)  //s1 = [2 3]

    // 截取s[0],s[1]，所以s1 = []int{1,2}
    s2 := s[:2]
    fmt.Printf("s2 = %v\n",s2)  //s2 = [1 2]

    // 截取s[0],s[1],s[1]，所以s1 = []int{1,2,3}
    s3 := s[0:]
    fmt.Printf("s3 = %v\n",s3)  //s3 = [1 2,3]

    //因为截取是浅拷贝，也就是只拷贝指针地址，所以值都会改变，简称浅拷贝
    s3[1] = 100

    fmt.Printf("s1 = %v\n",s1)
    fmt.Printf("s2 = %v\n",s2)
    fmt.Printf("s3 = %v\n",s3)

    //copy 可以将底层数据的slice一起进行拷贝，简称深拷贝
    s4 := make([]int,3)
    copy(s4,s)
    fmt.Printf("s4 = %v\n",s4)
}